import re

# 读取输入文件的内容
with open('input.txt', 'r') as f:
    input_text = f.read()

# 使用正则表达式匹配所有以 #word 开头的内容，并提取出其中的单词和内容
pattern = r'#word\s+(\w+)\s+([\s\S]*?)(?=#word|$)'
matches = re.findall(pattern, input_text)

# 对于每个匹配结果，将内容保存到以单词命名的文件中
for match in matches:
    word = match[0]
    content = match[1].strip()
    filename = f'{word}.txt'
    with open(filename, 'w') as f:
        f.write(f'#word {word} {content}\n')
